//
//  PersonInfoViewController.m
//  DanaKreditLoan
//
//  Created by ZhengChengFeng on 2024/10/21.
//

#import "PersonInfoViewController.h"
#import "ApplyTableViewCell.h"
#import "SinglePickerView.h"
#import "PickerCityView.h"

#import "OrderDetailModel.h"
#import "IdCardVertifyModel.h"
#import "IdCardViewController.h"
#import "IdCardFaceViewController.h"
#import "IdCardSuccessViewController.h"
#import "ContactInfoViewController.h"
#import "BankCardInfoViewController.h"

#define kTabCell   @"kTabCell"

#define kFootViewHeight  (15 + 48 + (IS_IPhoneX_All ? kHeight_BottomSafe : 15))

@interface PersonInfoViewController ()<CLLocationManagerDelegate>

@property (nonatomic) OrderDetailModel *orderDetModel;


@property (nonatomic) CLLocationManager *locationManager;
@property (nonatomic) NSTimer *timer;
@property (nonatomic) NSInteger timeInt;
@property (nonatomic) BOOL isLocationSuccess;
@property (nonatomic) NSString *startTimeStr1,*endTimeStr1;

@property (nonatomic) NSInteger type;

@property (nonatomic) CLLocationManager *locationManager2;
@property (nonatomic) NSTimer *timer2;
@property (nonatomic) NSInteger timeInt2;
@property (nonatomic) BOOL isLocationSuccess2;
@property (nonatomic) NSString *startTimeStr2,*endTimeStr2;

@end

@implementation PersonInfoViewController

- (void)back{
    [[DKCore sharedDKCore] jumpWLAlertView:^{
        [[self getCurrentVC] jumpToPopControlClass:@"OrderDetailViewController"];
    }];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    self.startTimeStr1 = [NSString getNowTimeTimestamp:@"yyyyMMdd HH:mm:ss"];
}

- (void)initFootView{

    UIView *bottomV = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight - kFootViewHeight - kNavigationBarHeight, kScreenWidth, kFootViewHeight)];
    bottomV.backgroundColor = kTableViewBackColor;
    [self.view addSubview:bottomV];
    
    
    UIButton *nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(15, 15, kScreenWidth - 30, 48)];
    nextBtn.titleLabel.font = [UIFont fontWithName:kFuturaMedium size:16];
    [nextBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
    [nextBtn setTitleColor:kWhiteColor forState:UIControlStateSelected];
    [nextBtn setTitleColor:kWhiteColor forState:UIControlStateHighlighted];
    [nextBtn setTitle:ASLocalizedString(@"Submit") forState:UIControlStateNormal];
    [nextBtn setTitle:ASLocalizedString(@"Submit") forState:UIControlStateSelected];
    [nextBtn setTitle:ASLocalizedString(@"Submit") forState:UIControlStateHighlighted];
    [nextBtn setImage:[UIImage imageNamed:@"icon_login2"] forState:UIControlStateNormal];
    [nextBtn setImage:[UIImage imageNamed:@"icon_login2"] forState:UIControlStateSelected];
    [nextBtn setImage:[UIImage imageNamed:@"icon_login2"] forState:UIControlStateHighlighted];
    [nextBtn addTarget:self action:@selector(clickSubmitBtn) forControlEvents:UIControlEventTouchUpInside];
    nextBtn.backgroundColor = kButtonDefaultColor;
    nextBtn.layer.cornerRadius = 24;
    nextBtn.layer.masksToBounds = YES;
    [bottomV addSubview:nextBtn];
    [nextBtn setImgRightTitltLeft:10];

}

- (void)initHeadView{
    UIView *headV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, DimensionBaseIphone6(220))];
    self.tableView.tableHeaderView = headV;
    
    UIImageView *imgV1 = [[UIImageView alloc] initWithFrame:CGRectMake(20, DimensionBaseIphone6(53), kScreenWidth - 40, DimensionBaseIphone6(118))];
    [headV addSubview:imgV1];
    imgV1.image = [UIImage imageNamed:@"icon_idcard1"];
    
    UIImageView *imgV2 = [[UIImageView alloc] initWithFrame:CGRectMake((kScreenWidth - DimensionBaseIphone6(184))/2, DimensionBaseIphone6(20), DimensionBaseIphone6(184), DimensionBaseIphone6(184))];
    [headV addSubview:imgV2];
    imgV2.image = [UIImage imageNamed:@"icon_personal"];
    
    
}


- (void)viewDidLoad {
    self.isTableViewStyleGrouped =  YES;
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tableView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - kFootViewHeight);
    [self loadData];
    
    [self.tableView registerClass:[ApplyTableViewCell class] forCellReuseIdentifier:kTabCell];
    
    
}

- (void)loadData{

    [BoxLoadingHelper showBoxLoadingWithMessage:@""];
    NSMutableDictionary *muDic = @{
        @"largely":esString(self.idStr),
    }.mutableCopy;
    [HttpNetHelper postNetworkHelperForPath:kPersonInfoUrl parameter:muDic onCompleteSuccess:^(NSDictionary * _Nonnull responseDic) {
        [BoxLoadingHelper hideBoxLoading];
        if ([responseDic[@"pineapples"] integerValue] != kSuccessCode) {
            [BoxLoadingHelper showBoxWithMessage:esString(responseDic[@"shin"])];
            return;
        }
        
        [self initHeadView];
        [self initFootView];
        
        NSDictionary *dic = responseDic[@"clip"];
        if (isArray(dic[@"shallow"])) {
            NSArray *arr = dic[@"shallow"];
            self.data = [ApplyModel mj_objectArrayWithKeyValuesArray:arr];
        }
        [self.tableView reloadData];
        
    } onCompleteFailur:^(NSError * _Nonnull error) {
        [BoxLoadingHelper hideBoxLoading];
    } withIsForm:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.data.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ApplyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTabCell];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = self.data[indexPath.section];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 83;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    ApplyTableViewCell *selCell = [tableView cellForRowAtIndexPath:indexPath];
    ApplyModel *mm  = selCell.model;
    
    if ([mm.bridge isEqualToString:kProvender]) {
        
        NSArray *appArr = mm.apprehend;
        NSMutableArray *singArr = [[NSMutableArray alloc] init];
        for (int i=0; i<appArr.count; i++) {
            ApprehendModel *md = [ApprehendModel mj_objectWithKeyValues:appArr[i]];
            [singArr addObject:md.hydrogen];
        }
        
        SinglePickerView *pickView = [[SinglePickerView alloc]init];
        for (int i = 0; i<singArr.count; i++) {
            if ([mm.favour isEqualToString:singArr[i]]) {
                pickView.selectInteger = i;
            }
        }
        [pickView pickViewWithArray:singArr andTitleStr:esString(mm.arrow)];
        [pickView showBottomView];
        [[UIApplication sharedApplication].keyWindow addSubview:pickView];
        
        pickView.block = ^(NSString *singleTitleString) {
            
            if ([singleTitleString isEqualToString:esString(mm.favour)]) {
                return;
            }
            
            for (int i=0; i<appArr.count; i++) {
                ApprehendModel *md = [ApprehendModel mj_objectWithKeyValues:appArr[i]];
                if ([md.hydrogen isEqualToString:singleTitleString]) {
                    mm.lord = md.lord;
                    break;
                }
            }
            
            mm.favour = esString(singleTitleString);
            [self.tableView reloadData];
            
            

        };
        
    }
    else if ([mm.bridge isEqualToString:kBeen]){
        
        NSArray *cityAry = [[NSUserDefaults standardUserDefaults] valueForKey:kCityDataAry];
        
        if (cityAry.count > 0) {
            PickerCityView *picker = [[PickerCityView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) withTitleStr:ASLocalizedString(@"Select Address") withDataArr:cityAry];
            [[UIApplication sharedApplication].keyWindow addSubview:picker];
            [picker showBottomView];
            picker.callbackCityStr = ^(NSString * _Nonnull cityStr) {
              
                mm.favour = esString(cityStr);
                [self.tableView reloadData];
            };
        }
        
    }
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *sectionView = [[UIView alloc] init];
    UIView *backV = [[UIView alloc] initWithFrame:CGRectMake(15, 0, kScreenWidth - 30, 20)];
    backV.backgroundColor = [UIColor whiteColor];
    [sectionView addSubview:backV];
    
    if (section == 0 && self.data.count > 0) {
        backV.layer.mask = [NSString UIBezierPathWithRect:backV.bounds withCorners:UIRectCornerTopLeft|UIRectCornerTopRight withRadiu:CGSizeMake(10, 10)];
    }
    
    return sectionView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 20.0f;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footView = [[UIView alloc] init];
    
    UIView *backV = [[UIView alloc] initWithFrame:CGRectMake(15, 0, kScreenWidth - 30, 20)];
    backV.backgroundColor = [UIColor whiteColor];
    
    if (section == self.data.count - 1 && self.data.count > 0) {
        [footView addSubview:backV];
        backV.layer.mask = [NSString UIBezierPathWithRect:backV.bounds withCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight withRadiu:CGSizeMake(10, 10)];
    }
    
    return footView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == self.data.count - 1 && self.data.count > 0 ) {
        return 20.0f;
    }
    return 0.00001f;
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

- (void)clickSubmitBtn{
    [self.view endEditing:YES];
    NSMutableDictionary *muDic = [NSMutableDictionary dictionary];
    [muDic setValue:esString(self.idStr) forKey:@"largely"];
    [muDic setValue:@"hundredsPersonalInfo" forKey:@"hundreds"];

    for (int i=0; i<self.data.count; i++) {
        ApplyModel *mm = [ApplyModel mj_objectWithKeyValues:self.data[i]];
        if ([mm.bridge isEqualToString:kProvender]) {
            [muDic setValue:esString(mm.lord) forKey:esString(mm.pineapples)];
        } else {
            [muDic setValue:esString(mm.favour) forKey:esString(mm.pineapples)];
        }
    }
    
    [BoxLoadingHelper showBoxLoadingWithMessage:@""];
    [HttpNetHelper postNetworkHelperForPath:kSavePersonInfoUrl parameter:muDic onCompleteSuccess:^(NSDictionary * _Nonnull responseDic) {
        [BoxLoadingHelper hideBoxLoading];
        if ([responseDic[@"pineapples"] integerValue] != kSuccessCode) {
            [BoxLoadingHelper showBoxWithMessage:esString(responseDic[@"shin"])];
            return;
        }
        
        self.endTimeStr1 = [NSString getNowTimeTimestamp:@"yyyyMMdd HH:mm:ss"];
        [self uploadMaiDianPersonInfoData];
        
        [self enterNextPage];
        
    } onCompleteFailur:^(NSError * _Nonnull error) {
        [BoxLoadingHelper hideBoxLoading];
    } withIsForm:YES];
    
}


/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

- (void)enterNextPage{
    
    [BoxLoadingHelper showBoxLoadingWithMessage:@""];
    NSMutableDictionary *muDic = @{
        @"largely":esString(self.idStr),
        @"mainland":@"mainlandOrderDet",
    }.mutableCopy;
    [HttpNetHelper postNetworkHelperForPath:kOrderDetailUrl parameter:muDic onCompleteSuccess:^(NSDictionary * _Nonnull responseDic) {
        [BoxLoadingHelper hideBoxLoading];
        [BoxLoadingHelper hideBoxLoadingFromView:self.view];
        if ([responseDic[@"pineapples"] integerValue] != kSuccessCode) {
            [BoxLoadingHelper showBoxWithMessage:esString(responseDic[@"shin"])];
            return;
        }
    
      
        NSDictionary *dic = responseDic[@"clip"];
       
        OrderDetailModel *model = [OrderDetailModel mj_objectWithKeyValues:dic];
        self.orderDetModel = model;
        
        if (PMObjectIsEmpty(model.swears)) {
            [self enterOrderH5Page];
            return;
        }
        if ([esString(model.swears.undiluted) isEqualToString:kIdCardInfoVertify]) {
            [self goIdCardVertify];
        }
        else if ([esString(model.swears.undiluted) isEqualToString:kContactInfoVertify]) {
            [self goContactVertify];
        }
        else if ([esString(model.swears.undiluted) isEqualToString:kBankInfoVertify]) {
            [self goBankVertify];
        }

        
    } onCompleteFailur:^(NSError * _Nonnull error) {
        [BoxLoadingHelper hideBoxLoading];
        [BoxLoadingHelper hideBoxLoadingFromView:self.view];
    } withIsForm:YES];
    

}
    

- (void)enterOrderH5Page{
        NSMutableDictionary *muDic = @{
            @"dosed":esString(self.orderDetModel.refugees.passages),
            @"founders":esString(self.orderDetModel.refugees.founders),
            @"weakness":esString(self.orderDetModel.refugees.weakness),
            @"shouldered":esString(self.orderDetModel.refugees.shouldered),
            @"guiding":@"guidingIdStr",
            @"excuse":@"excuseIdStr",
        }.mutableCopy;
    self.startTimeStr2 = [NSString getNowTimeTimestamp:@"yyyyMMdd HH:mm:ss"];
        [BoxLoadingHelper showBoxLoadingWithMessage:@""];
        [HttpNetHelper postNetworkHelperForPath:kOrderNoUrl parameter:muDic onCompleteSuccess:^(NSDictionary * _Nonnull responseDic) {
            [BoxLoadingHelper hideBoxLoading];
            if ([responseDic[@"pineapples"] integerValue] != kSuccessCode) {
                [BoxLoadingHelper showBoxWithMessage:esString(responseDic[@"shin"])];
                return;
            }
            
            self.endTimeStr2 = [NSString getNowTimeTimestamp:@"yyyyMMdd HH:mm:ss"];
            [self uploadMaiDianSDStartData];
        
            NSDictionary *dic = responseDic[@"clip"];
            
            [[DKCore sharedDKCore] jumpToControllerWithUrlString:esString(dic[@"twentieth"])];
          
        } onCompleteFailur:^(NSError * _Nonnull error) {
            [BoxLoadingHelper hideBoxLoading];
        } withIsForm:YES];
        
}


- (void)goIdCardVertify{
    [BoxLoadingHelper showBoxLoadingWithMessage:@""];
    NSMutableDictionary *muDic = @{
        @"largely":esString(self.idStr),
        @"enabled":@"enabledIdCard"
    }.mutableCopy;
    [HttpNetHelper getNetworkHelperForPath:kGetIdCardInfoUrl parameter:muDic onCompleteSuccess:^(NSDictionary * _Nonnull responseDic) {
        [BoxLoadingHelper hideBoxLoading];
        if ([responseDic[@"pineapples"] integerValue] != kSuccessCode) {
            [BoxLoadingHelper showBoxWithMessage:esString(responseDic[@"shin"])];
            return;
        }
        
        NSDictionary *dic = responseDic[@"clip"];
        
        IdCardVertifyModel *model = [IdCardVertifyModel mj_objectWithKeyValues:dic];
        
        
        if ([model.ego.keller integerValue] == 0) {
            IdCardViewController *vc = [[IdCardViewController alloc] init];
            vc.idStr = esString(self.idStr);
            vc.orderNoStr = esString(self.orderDetModel.refugees.passages);
            vc.title = esString(self.orderDetModel.swears.arrow);
            [self.navigationController pushViewController:vc animated:YES];
        }
        
        else if ([model.immunity.keller integerValue] == 0 ){
            IdCardFaceViewController *vc = [[IdCardFaceViewController alloc] init];
            vc.idStr = esString(self.idStr);
            vc.orderNoStr = esString(self.orderDetModel.refugees.passages);
            vc.title = esString(self.orderDetModel.swears.arrow);
            [self.navigationController pushViewController:vc animated:YES];
        }
        else{
            IdCardSuccessViewController *vc = [[IdCardSuccessViewController alloc] init];
            vc.nameStr = esString(model.ego.pureness.hydrogen);
            vc.idNoStr = esString(model.ego.pureness.shyly);
            vc.birDateStr = esString(model.ego.pureness.flattered);
            vc.idStr = esString(self.idStr);
            vc.orderNoStr = esString(self.orderDetModel.refugees.passages);
            [self.navigationController pushViewController:vc animated:YES];
        }
        
        
        
    } onCompleteFailur:^(NSError * _Nonnull error) {
        [BoxLoadingHelper hideBoxLoading];
    } withIsForm:NO];
    
}


- (void)goContactVertify{
    ContactInfoViewController *vc = [[ContactInfoViewController alloc] init];
    vc.idStr = esString(self.idStr);
    vc.orderNoStr = esString(self.orderNoStr);
    vc.title = esString(self.orderDetModel.swears.arrow);
    [self.navigationController pushViewController:vc animated:YES];
}


- (void)goBankVertify{
    BankCardInfoViewController *vc = [[BankCardInfoViewController alloc] init];
    vc.idStr = esString(self.idStr);
    vc.orderNoStr = esString(self.orderNoStr);
    vc.title = esString(self.orderDetModel.swears.arrow);
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark ----- uploadMaiDianPersonInfoData -------
- (void)uploadMaiDianPersonInfoData{
    self.timeInt = 0;
    self.isLocationSuccess = NO;
    [self initLocation];
}

- (void)initLocation{
    self.timer = [NSTimer timerWithTimeInterval:1.f target:self selector:@selector(addTimer) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
    
    self.locationManager = [[CLLocationManager alloc]init];
    self.locationManager.delegate = self;
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    self.locationManager.distanceFilter = 100;
    [self.locationManager requestWhenInUseAuthorization];
    [self.locationManager requestLocation];
}

- (void)addTimer{
    self.timeInt ++;
    if (self.isLocationSuccess) {
        [self.timer invalidate];
        self.timer = nil;
        self.timeInt = 0;
    }
    else{
        if (self.timeInt > 8) {
            [self.timer invalidate];
            self.timer = nil;
            self.timeInt = 0;
            NSString *longitudeStr = [[NSUserDefaults standardUserDefaults] objectForKey:kStoreLongitude];
            NSString *latitudeStr = [[NSUserDefaults standardUserDefaults] objectForKey:kStoreLatitude];
            
            [self goServer1WithLongitudeStr:PMStringIsEmpty(longitudeStr) ? @"" : longitudeStr withLatitudeStr:PMStringIsEmpty(latitudeStr) ? @"" : latitudeStr];
            
        }
    }
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
    
    CLLocation *newlocation = locations[0];
    NSString *longitudeStr = [NSString stringWithFormat:@"%lf",newlocation.coordinate.longitude];
    NSString *latitudeStr =  [NSString stringWithFormat:@"%lf",newlocation.coordinate.latitude];
    
    if (manager == self.locationManager) {
        [self.locationManager stopUpdatingLocation];
    } else {
        [self.locationManager2 stopUpdatingLocation];
    }
    
    
    
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:kStoreLongitude];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:kStoreLatitude];
    [[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithFormat:@"%lf",newlocation.coordinate.longitude] forKey:kStoreLongitude];
    [[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithFormat:@"%lf",newlocation.coordinate.latitude] forKey:kStoreLatitude];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
    if (self.type == 2) {
        self.isLocationSuccess2 = YES;
        
        if (self.timeInt2 <= 8) {
            [self goServer2WithLongitudeStr:esString(longitudeStr) withLatitudeStr:esString(latitudeStr)];
        }
        
    } else {
        self.isLocationSuccess = YES;
        
        if (self.timeInt <= 8) {
            [self goServer1WithLongitudeStr:esString(longitudeStr) withLatitudeStr:esString(latitudeStr)];
        }
    }

}

- (void)goServer1WithLongitudeStr:(NSString *)longitudeStr withLatitudeStr:(NSString *)latitudeStr{
    [DataCategoryUpload uploadMaiDianData:@"4" withOrderIdStr:self.idStr withOrderNoStr:esString(self.orderNoStr) withLongitude:esString(longitudeStr) withLatitude:esString(latitudeStr) withStartTime:self.startTimeStr1 withEndTime:self.endTimeStr1];
}

- (void)goServer2WithLongitudeStr:(NSString *)longitudeStr withLatitudeStr:(NSString *)latitudeStr{
    [DataCategoryUpload uploadMaiDianData:@"8" withOrderIdStr:self.idStr withOrderNoStr:esString(self.orderNoStr) withLongitude:esString(longitudeStr) withLatitude:esString(latitudeStr) withStartTime:self.startTimeStr2 withEndTime:self.endTimeStr2];
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
    
}


#pragma mark ----- uploadMaiDianSDStartData ------
- (void)uploadMaiDianSDStartData{
    self.type = 2;
    self.timeInt2 = 0;
    self.isLocationSuccess2 = NO;
    [self initLocation2];
}

- (void)initLocation2{
    
    self.timer2 = [NSTimer timerWithTimeInterval:1.f target:self selector:@selector(addTimer2) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:self.timer2 forMode:NSRunLoopCommonModes];
    
    self.locationManager2 = [[CLLocationManager alloc]init];
    self.locationManager2.delegate = self;
    self.locationManager2.desiredAccuracy = kCLLocationAccuracyBest;
    self.locationManager2.distanceFilter = 100;
    [self.locationManager2 requestWhenInUseAuthorization];
    [self.locationManager2 requestLocation];
}

- (void)addTimer2{
    self.timeInt2 ++;
    if (self.isLocationSuccess2) {
        [self.timer2 invalidate];
        self.timer2 = nil;
        self.timeInt2 = 0;
    }
    else{
        if (self.timeInt2 > 8) {
            [self.timer2 invalidate];
            self.timer2 = nil;
            self.timeInt2 = 0;
            NSString *longitudeStr = [[NSUserDefaults standardUserDefaults] objectForKey:kStoreLongitude];
            NSString *latitudeStr = [[NSUserDefaults standardUserDefaults] objectForKey:kStoreLatitude];
            
            [self goServer2WithLongitudeStr:PMStringIsEmpty(longitudeStr) ? @"" : longitudeStr withLatitudeStr:PMStringIsEmpty(latitudeStr) ? @"" : latitudeStr];
            
        }
    }
}


@end

